﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using PCMSofCC.BLL;

namespace PCMSofCC.Admin
{
    public partial class AddSite : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GoogleMapForASPNet1.PushpinMoved += new GoogleMapForASPNet.PushpinMovedHandler(OnPushpinMoved);
            if (!IsPostBack)
            {
                GoogleMapForASPNet1.GoogleMapObject.APIKey = ConfigurationManager.AppSettings["GoogleAPIKey"];
                GoogleMapForASPNet1.GoogleMapObject.APIVersion = "2";
                GoogleMapForASPNet1.GoogleMapObject.Width = "590px";
                GoogleMapForASPNet1.GoogleMapObject.Height = "489px";
                GoogleMapForASPNet1.GoogleMapObject.ZoomLevel = 12;
                GoogleMapForASPNet1.GoogleMapObject.AutomaticBoundaryAndZoom = false;
                GooglePoint GP = new GooglePoint("1", 30.59, 114.30);
                GoogleMapForASPNet1.GoogleMapObject.CenterPoint = GP;
                GP.Draggable = true;
                GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP);
            }
        }

        void OnPushpinMoved(string pID)
        {
            GooglePoint GP = GoogleMapForASPNet1.GoogleMapObject.Points["1"];
            lblPosition.Text = GP.Latitude.ToString("f4") + ", " + GP.Longitude.ToString("f4");
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            string name = SiteName.Text;
            string number = SiteNumber.Text;
            string address = SiteAddress.Text;
            GooglePoint GP = GoogleMapForASPNet1.GoogleMapObject.Points["1"];
            double lati = GP.Latitude;
            double lon = GP.Longitude;
            int companyId = int.Parse(SiteCompany.SelectedValue);
            Sites.AddSite(name,number,address,lon,lati,companyId);
            SiteName.Text = "";
            SiteNumber.Text = "";
            SiteAddress.Text = "";
        }
    }
}
